#include<iostream>

using namespace std;
const int N=5e5+10;

int tree[N][26],e[N];
int idx=0;
void insert(string s)
{
	int cur=0;
	for(auto&e:s)
	{
		int flag=e-'a';
		if(tree[cur][flag]==0)
			tree[cur][flag]=++idx;
		cur=tree[cur][flag];
	}
	e[cur]++;
}

int find(string s)
{
	int cur=0;
	for(auto&e:s)
	{
		int flag=e-'a';
		if(tree[cur][flag]==0)
			return 0;
		cur=tree[cur][flag];
	}
	return e[cur]++;
}

int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		string s;cin>>s;
		insert(s);
	}

	int m;cin>>m;

	for(int i=1;i<=m;i++)
	{
		string s;cin>>s;
		int flag=find(s);
		if(flag==0) cout<<"WRONG"<<endl;
		else if(flag==1) cout<<"OK"<<endl;
		else cout<<"REPEAT"<<endl;
	}
	return 0;
}